using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using DTO;
using Utility;

namespace BUS
{
    public class CTHoaDon_BUS
    {
        public static void Insert(CTHoaDon_DTO ctHoaDon)
        {
            CTHoaDon_DAL ctHoaDonDAL = new CTHoaDon_DAL();
            ctHoaDonDAL.Insert(ctHoaDon);
        }
        public static void Update(CTHoaDon_DTO ctHoaDon)
        {
            CTHoaDon_DAL ctHoaDonDAL = new CTHoaDon_DAL();
            ctHoaDonDAL.Update(ctHoaDon);
        }
        public static void Delete(int iD,int matHang)
        {
            CTHoaDon_DAL ctHoaDonDAL = new CTHoaDon_DAL();
            ctHoaDonDAL.Delete(iD,matHang);
        }
        public static tbCTHoaDonCollection Get(string where,int pageindex,int pagesize,string orderby,string orderdirection,out int total)
        {
            CTHoaDon_DAL ctHoaDonDAL = new CTHoaDon_DAL();
            return ctHoaDonDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbCTHoaDonCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            CTHoaDon_DAL ctHoaDonDAL = new CTHoaDon_DAL();
            return ctHoaDonDAL.Get(cri.Criter, 0, 0, tbCTHoaDonColumns.MaHD.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static CTHoaDon_DTO GetByID(int iD)
        {       int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbCTHoaDonColumns.MaHD.ToString(), Condition.EQUAL, iD);
            CTHoaDon_DAL ctHoaDonDAL = new CTHoaDon_DAL();
            tbCTHoaDonCollection ctHoaDonCollection = ctHoaDonDAL.Get(cri.Criter,
                0, 0, tbCTHoaDonColumns.MaHD.ToString(), OrderDirection.ASC.ToString(), out total);
            if (ctHoaDonCollection.Count > 0)
                return ctHoaDonCollection[0];
            return null;
        }
        public static tbCTHoaDonCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            CTHoaDon_DAL ctHoaDonDAL = new CTHoaDon_DAL();
            return ctHoaDonDAL.Get(cri.Criter, 1, number,
                tbCTHoaDonColumns.MaHD.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbCTHoaDonCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            CTHoaDon_DAL ctHoaDonDAL = new CTHoaDon_DAL();
            return ctHoaDonDAL.Get(cri.Criter, 1, number,
                tbCTHoaDonColumns.MaHD.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
